package com.tanhua.back.utils;

import com.tanhua.back.entity.Admin;

public class ThreadLocalUtil {
    private static ThreadLocal<Admin> threadLocal=new ThreadLocal<>();
    //将用户对象存入ThreadLocal
    public static void set(Admin admin){
        threadLocal.set(admin);
    }
    //从当前线程获取用户对象id
    public static Long getId(){
        return threadLocal.get().getId();
    }
    //从当前线程中获取用户手机号
    public static String getUsername(){
        return threadLocal.get().getUsername();
    }
   //清除
    public static void close(){
        threadLocal.remove();
    }
}